package com.intmall.train.mybatis;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.util.ArrayList;
import java.util.List;

public class CustomMyBatisGenerator {
    public static void main(String[] args) throws Exception {
        // 逆向工程
        List<String> warnings = new ArrayList<>();
        boolean overwrite = true;
        ConfigurationParser cp = new ConfigurationParser(warnings);
        // 读取生成配置文件
        Configuration config = cp.parseConfiguration(CustomMyBatisGenerator.class.getClassLoader().getResourceAsStream("generator-config-member.xml"));
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
        // 输入告警或错误信息
        System.out.println(warnings);
    }
}
